package com.prs.crm.service.oa.impl;

import java.io.File;
import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.oa.WorkSummaryDao;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.WorkSummary;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.WorkSummaryService;

public class WorkSummaryServiceImpl extends BaseServiceImpl<WorkSummary,WorkSummaryDao> implements WorkSummaryService{
	private PersonService personService;
	@Override
	public void saveWorkSummary(WorkSummary workSummary, File file,
			String fileName,String copyToPersons) {
		// TODO Auto-generated method stub
		Attach attach = FileUtil.getInstance().saveFile(file, fileName, "", Constrains.UPLOAD_DIC_WORKSUMMARY);
		if(attach.getSrc() != null) {
			workSummary.setAttach(attach.getSrc());
		}
		Collection<Person> persons = personService.findPersons(ToolKits.convertStringAryToIntAry(copyToPersons.split(",")));
		workSummary.addCopyToPersons(persons);
		workSummary.setRecorder(AppContext.getAccountContext().currentUser());
		workSummary.setRecordTime(new Date());
 		this.getDao().save(workSummary);
	}
	
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public PersonService getPersonService() {
		return personService;
	}

	@Override
	public Collection<WorkSummary> getAllWorkSummary() {
		// TODO Auto-generated method stub
		return this.getDao().getAllWorkSummary();
	}

	@Override
	public Collection<WorkSummary> getWorkSummaryByIds(Integer[] ids) {
		// TODO Auto-generated method stub
		return this.getDao().getWorkSummaryByIds(ToolKits.convertToIntAry(ids));
	}

	@Override
	public Collection<WorkSummary> getAuditWorkSummary(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getAuditWorkSummary(person);
	}

	@Override
	public Collection<WorkSummary> getValidCritiqueWorkSummary(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidCritiqueWorkSummary(person);
	}

}
